<template>
  <div class="form-add">
    <div class="form-container">
      <div class="form-header">
        <el-button @click="cancel" size="small">返回</el-button>
        <el-button type="primary" @click="sure" size="small">保存</el-button>
      </div>
      <div class="form-content">
        <el-form ref="form" :model="form" label-width="100px">
          <el-form-item label="权限组名称">
            <el-input v-model="form.GroupName"></el-input>
          </el-form-item>
          <el-form-item label="状态">
            <el-radio-group v-model="form.Status">
              <el-radio :label="1">启用</el-radio>
              <el-radio :label="0">停用</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>

export default {
  name: 'Edit',
  props: ['data'],
  data() {
    return {
      form: {
        Status: 1
      },
    }
  },
  mounted() {
    this.info();
  },
  methods: {
    sure: function () {
      let url = 'add';
      if (this.data && this.data.PurviewGroupId) {
        url = 'update'
      }
      let req = {
        GroupName: this.form.GroupName,
        Status: this.form.Status,
      };
      if (this.data && this.data.PurviewGroupId) {
        req.PurviewGroupId = this.data.PurviewGroupId;
      }
      console.log('请求参数', req);
      this.$message.success('保存成功');
      this.$emit('sure') // 保存回调父组件方法
    },

    cancel: function () {
      this.$emit('cancel') // 返回回调父组件方法
    },
    info: function () {
      if (!this.data || !this.data.PurviewGroupId) {
        return;
      }
      this.form = this.data;
    },
  }
}
</script>
